package 密码管理系统;
import java.io.IOException;
import java.util.Scanner;
public class Main {
    public static void main(String args []){
    Inlet inlet = new Inlet();
    inlet.boundary();
    }
}
class Inlet{
    Scanner input = new Scanner(System.in);
    public void  boundary(){                    //程序进入界面
        System.out.println("------------------------");
        System.out.println("欢迎使用密码管理系统");
        System.out.println("------------------------");
        System.out.println("请选择你的操作：");
        System.out.println("1. 加密");
        System.out.println("2. 解密");
        System.out.println("3. 判断密码强度");
        System.out.println("4. 密码生成");
        System.out.println("5. 退出");
        System.out.print("请输入选项序号：");
        int number = input.nextInt();
        judge(number);   //通过用户输入数字跳转功能
    }
    public void judge(int sum){      //判断输入数字并使用功能方法，以及循环
        int number = sum;
        if(sum == 1) {
            this.process();
            this.transition();
            this.boundary();
        }
        if(sum == 2){
            this.untie();
            this.transition();
            this.boundary();
        }
        if(sum == 3){              //未完成功能

        }
        if(sum == 4){

        }
        if(sum == 5){
            System.out.println("退出成功");
        }
    }
    public void  process(){       //加密功能方法
        Scanner put = new Scanner(System.in);
        System.out.print("请输入要加密的数字密码：");
        String result = put.nextLine();
        char [] CharArry = result.toCharArray();
        int [] SumArry = new int[CharArry.length];   //将字符数组转换为整数数组
        for(int i = 0; i < SumArry.length ;i++){    //将每个字符的ASCII码加上它在字符串中的位置(1开始)和偏移值3
            SumArry[i] = CharArry[i] + 4 + i;
        }
            int sum = SumArry[0];                       //将字符串的第一位和最后一位调换顺序
            SumArry[0] = SumArry[SumArry.length - 1];
            SumArry[SumArry.length - 1] = sum;
            int a = 0;                                  //将字符串反转
            for (int i = SumArry.length - 1; i > a; i--) {
                sum = SumArry[a];
                SumArry[a] = SumArry[i];
                SumArry[i] = sum;
                a++;
            }
            for (int i = 0; i < CharArry.length; i++) {         //将整数数组转换为字符数组
                CharArry[i] = (char) SumArry[i];
            }
            System.out.print("加密后的结果是：" );
            System.out.println(CharArry);
        }

    public void untie(){            //解密功能方法
        Scanner put = new Scanner(System.in);
        System.out.print("请输入要解密的数字密码：");
        String result = put.nextLine();
        char [] CharArry = result.toCharArray();
        int [] SumArry = new int[CharArry.length];        //将字符数组转换为整数数组
        for(int i = 0; i < SumArry.length ;i++){
            SumArry[i] = CharArry[i];
        }
        int sum;                                        //将字符串反转
        int a = 0;
        for (int i = SumArry.length - 1; i > a; i--) {
            sum = SumArry[a];
            SumArry[a] = SumArry[i];
            SumArry[i] = sum;
            a++;
        }
        sum = SumArry[0];                            //将字符串的第一位和最后一位调换顺序
        SumArry[0] = SumArry[SumArry.length - 1];
        SumArry[SumArry.length - 1] = sum;
        for (int i = 0; i < CharArry.length; i++) {            //解决乱码
            CharArry[i] = (char) SumArry[i];
        }
        for(int i = 0; i < SumArry.length ;i++) {
            SumArry[i] = CharArry[i];
        }
        for(int i = 0; i < SumArry.length ;i++){     //将每个字符的ASCII码减上它在字符串中的位置(1开始)和偏移值3
            SumArry[i] = CharArry[i] -4 - i;
        }
        for (int i = 0; i < CharArry.length; i++) {
            CharArry[i] = (char) SumArry[i];
        }
        System.out.print("解密后的结果是：" );
        System.out.println(CharArry);
    }
    public void transition()  {            //任意键返回方法
        System.out.println("按任意键返回(需要回车)");
        try {
            System.in.read();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
//TFG添加了注释
System.out.print("Hello World");